package logic

import (
	"context"
	"mall/services/distributed-id/rpc/internal/mapper/entity"
	"mall/services/distributed-id/rpc/internal/svc"
	"mall/services/distributed-id/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateTagLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateTagLogic {
	return &CreateTagLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateTagLogic) CreateTag(in *pb.CreateTagReq) (*pb.CreateTagResp, error) {
	useCase := l.svcCtx.SegmentUseCase
	out := &pb.CreateTagResp{}
	err := useCase.CreateTag(l.svcCtx.DBEngin, &entity.Segments{
		BizTag: in.GetTag(),
		MaxId:  in.GetMaxId(),
		Step:   in.GetStep(),
		Remark: in.GetRemark(),
	})
	if err != nil {
		return nil, err
	}

	return out, nil
}
